<template>
    <div class="banner" :style="{
      backgroundColor: config.pageConfig.color,
    }">
        <div :style="{
          marginTop: config.pageConfig.marginTop + 'px',
          marginBottom: config.pageConfig.marginBottom + 'px',
        }">
            <div :style="{
                borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
                borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
            }"
            class="hotspot-area"
            >
                <img :src="config.pageConfig.imgUrl" id='myImage' :style="{
                    borderTopLeftRadius: config.pageConfig.radiusTop + 'px',
                    borderTopRightRadius: config.pageConfig.radiusTop + 'px',
                    borderBottomLeftRadius: config.pageConfig.radiusBottom + 'px',
                    borderBottomRightRadius: config.pageConfig.radiusBottom + 'px',
                }" @load="getImageSize"/>
                <div v-for="item in config.pageConfig.zones" @click="tolink(item.url)" :style="{
                    top:item.topPer*rh+'px',
                    left:item.leftPer*rw+'px',
                    width:item.widthPer*rw+'px',
                    height:item.heightPer*rh+'px'
                }"></div>
            </div>
        </div>
    </div>
</template>
<script lang="ts">
export default {
    name: "Hot",
};
</script>
<script lang="ts" setup>
import { reactive, onMounted } from "vue";
const config = defineProps({
    pageConfig: {
        type: Object,
        default: {
            color: "",
            marginTop: 0,
            marginBottom: 0,
            marginImg: 5,
            margin: 0,
            radiusTop: 0,
            radiusBottom: 0,
            imgUrl:"",
            zones:[]
        },
    },
    show: {
    type: Boolean,
    default: true,
  },
});
let emits = defineEmits<{ (e: "close", flag: boolean): void }>();
const tolink = (url: string) => {
  if (url && config.show == false) {
    window.location.href = url;
  }
};
const rw=ref(0)
const rh=ref(0)

const getImageSize=()=>{
    const myimage = document.getElementById("myImage");
    rw.value = myimage.width;
    rh.value = myimage.height;
}
</script>
<style lang="scss" scoped>
.banner {
    width: 100%;
    overflow: hidden;
}
.hotspot-area{
    width:100%;
    position:relative;
    img{
        width:100%;
    }
    div{
        position:absolute;
        background:transparent;
    }
}
</style>
  